<?php

namespace App\Models\Landscaping;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class TaskCategory extends Model
{
    use SoftDeletes;
    protected $table = 'task_categories';
    public $primaryKey = 'id';
    protected $guarded = [];

    protected $hidden = ['deleted_at','created_at','updated_at'];

    //查询list
    public function getList($request)
    {
        $per_page = $request->input('per_page',10);
        return self::orderBy('sort','desc')
            ->where(function($query) use ($request){
                //检测当前的请求中是否包含name参数
                $name = $request->input('name', '');//设备类型名称
                if(!empty($name)) {
                    $query->where('name','like','%'.$name.'%');
                }
            })
            ->paginate($per_page);
    }
}
